package Draw0513;

import java.awt.*;

public class ShapeV2 {
    int x1,x2,x3,x4,x5;
    int y1,y2,y3,y4,y5;
    String type = "";
    Color color = Color.BLACK;

    public ShapeV2(){

    }

    public ShapeV2(int x1,int y1,int x2,int y2,Color color,String str){
        this.x1 = x1;
        this.y1 = y1;
        this.x2 = x2;
        this.y2 = y2;
        this.color = color;
        type = str;
    }

    public void drawShapeV2(Graphics g){
        g.setColor(color);
        switch (type){
            case "直线":
                g.drawLine(x1,y1,x2,y2 );
                break;
            case "矩形":
                g.drawRect(Math.min(x1,x2), Math.min(y1,y2), Math.abs(x1 - x2), Math.abs(y1 - y2));
                break;
            case "圆形":
                double center_x = (double) (x1 + x2) /2;
                double center_y = (double) (y1 + y2) /2;
                double round = Math.min(Math.abs(x2 - x1), Math.abs(y2 - y1)) * 0.5;
                double d;
                for (int i = y1; i <= y2; i++) {
                    for (int j = x1; j <= x2 ; j++) {
                        d = Math.sqrt(Math.pow((j - center_x),2) + Math.pow((i - center_y),2));
                        if (d >= round - 1 && d <= round + 1){  //提供误差范围，确保图形完整
                            g.fillRect(j,i,1,1);
                        }
                    }
                }
                break;
            case "实心矩形":
                g.fillRect(Math.min(x1,x2), Math.min(y1,y2), Math.abs(x1 - x2), Math.abs(y1 - y2));
                break;
            case "实心圆形":
                center_x = (double) (x1 + x2) /2;
                center_y = (double) (y1 + y2) /2;
                round = Math.min(Math.abs(x2 - x1), Math.abs(y2 - y1)) * 0.5;
                for (int i = y1; i <= y2; i++) {
                    for (int j = x1; j <= x2 ; j++) {
                        d = Math.sqrt(Math.pow((j - center_x),2) + Math.pow((i - center_y),2));
                        if (d <= round + 1){  //提供误差范围，确保图形完整
                            g.fillRect(j,i,1,1);
                        }
                    }
                }
                break;
            case "等腰三角形":
                g.drawLine(Math.min(x1, x2), Math.max(y1, y2), Math.max(x1, x2), Math.max(y1, y2));
                g.drawLine(Math.min(x1, x2), Math.max(y1, y2), (x1+ x2) / 2, Math.min(y1, y2));
                g.drawLine(Math.max(x1, x2), Math.max(y1, y2), (x1+ x2) / 2, Math.min(y1, y2));
                break;

        }
    }
}










